/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import { templateBlack } from '@/services/cloudCall';
import { Modal, Form, Input, Row, message } from 'antd';
import React from 'react';

const { TextArea } = Input;

interface ModalType {
  visible?: boolean;
  courierPhone?: string;
  tplId?: string;
  onCancel: () => void;
  onReFresh: () => void;
}

const BlackModal: React.FC<ModalType> = (props) => {
  const { visible, courierPhone = '', tplId = '', onCancel, onReFresh } = props;
  const [form] = Form.useForm();
  const onSubmit = async () => {
    const { note } = form.getFieldsValue();
    if (!note) {
      message.error('请输入拉黑原因');
      return;
    }
    const { code, msg } = await templateBlack({ tplId, courierPhone, note });
    if (code == '0') {
      message.info('操作成功');
      form.resetFields();
      onCancel();
      onReFresh();
    } else {
      message.error(msg);
    }
  };

  return (
    <Modal
      visible={visible}
      centered
      title='温馨提示'
      width={400}
      onCancel={onCancel}
      onOk={onSubmit}
    >
      <Row>确定拒绝并拉黑此模版？</Row>
      <Row>拉黑后，用户将无法使用短信、云呼、网络电话</Row>
      <Form form={form} style={{ marginTop: 20 }}>
        <Form.Item name='note'>
          <TextArea maxLength={100} allowClear showCount placeholder='请填写拉黑原因' />
        </Form.Item>
      </Form>
    </Modal>
  );
};

export default BlackModal;
